package com.gnerv.sylvanas.deploy.storage;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.IOException;

@Slf4j
@Service
public class DeployStorageService {

    public boolean saveFile(String fileName, String fileContent) {
        boolean exists = new File(fileName).exists();
        if (!exists) {
            try {
                FileCopyUtils.copy(fileContent.getBytes(), new File(fileName));
            }  catch (IOException e) {
                log.error(e.getMessage());
            }
        }else  {
            new File(fileName).delete();
        }
        return true;
    }



}
